from PySide6.QtCore import QDateTime, Slot, Qt
from PySide6.QtWidgets import QMessageBox, QDialog, QTableWidgetItem, QMainWindow, QButtonGroup
from PySide6.QtGui import QIcon, QColor

from Devices.Chiot.BsDevs.ComDev.Forms.ComDevWindow import ComDevWindow
from Devices.Chiot.BsDevs.Water.WaterDevice import WaterDevice
from Devices.Chiot.BsDevs.Water.WaterParser import WaterParser
from Devices.Chiot.BsDevs.Water.Forms.WaterWindow_UI import Ui_FormWaterWindow
from Components.MessageBoxFunc import MessageBoxFunc

class WaterWindow(ComDevWindow):
    # 0、窗体初始化、状态变量初始化
    def __init__(self, supportDevice, parent = None):
        # 注意在实现特有设备时，一定要先将其ui对象加载完毕
        super().__init__(supportDevice, parent)
        self.FullStatus = WaterDevice.WaterFullStatus()

        self._ui = Ui_FormWaterWindow()
        self._ui.setupUi(self)
        self.initUiWindow()
        self.SetupUi(self._ui)
        # self.testUi()

    # 1、数据解析
    def setHeartbeatStatus(self):
        pass

    def CmdRptStatusReceived(self, msgValue):
        if WaterParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdHeartbeatReceived(self, msgValue):
        if WaterParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdFullStatusReceived(self, msgValue):
        pass

    def CmdMsgValueReceived(self, msgName, msgValue):
        pass

    # 2、运行状态
    def setFullStatus(self):                          
        self._ui.label_sensorStatus.setText("浸水报警" if self.FullStatus.sensorStatus else "未浸水")
        self._ui.label_powerWarn.setText("告警" if self.FullStatus.powerWarn else "未告警")
        self._ui.label_batteryPercentage.setText(str(self.FullStatus.batteryPercentage) + "%")
        self._ui.label_checkStatus.setText("正在自检" if self.FullStatus.checkStatus else "未自检")
      